/**
 * 
 */
package edu.buu.refectory.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.buu.refectory.domain.Cart;
import edu.buu.refectory.service.CartService;

/**
 * @author Bruce<br>
 * @version 1.0<br>
 * @CreateDate 1 May 2016 <br>
 */
@RequestMapping("cart")
@Controller
public class CartController {
	
	@Autowired
	private CartService cartService;

	@RequestMapping("add")
	@ResponseBody
	public ResponseEntity<?> addCart(@RequestParam("fId") Integer fId,HttpSession session){
		Cart cart= cartService.addCart(fId,session);
		return new ResponseEntity<Object>(cart,HttpStatus.CREATED);
	}
	
//	@RequestMapping("list")
//	public String listCart(HttpServletRequest request, HttpSession response,
//			Model model){
//		//查询购物车列表
//		List<EbCart> cartList = cartService.listCart(request,session);
//		model.addAttribute("cartList", cartList);
//		//计算商品总个数和总金额
//		Integer itemNum = 0;
//		BigDecimal totalPrice = new BigDecimal(0);
//		for(EbCart cart : cartList){
//			itemNum = itemNum + cart.getQuantity();
//			totalPrice = cart.getSku().getSkuPrice().multiply(new BigDecimal(cart.getQuantity())).add(totalPrice);
//		}
//		model.addAttribute("itemNum", itemNum);
//		model.addAttribute("totalPrice", totalPrice);
//		return "shop/car";
//	}
	
//	@RequestMapping("/changeNum")
//	public String changeNum(HttpServletRequest request, HttpServletResponse response,
//			Long skuId, Integer quantity){
//		cartService.updateCartNum(request, response, skuId, quantity);
//		return "redirect:listCart.do";
//	}
//	
//	@RequestMapping("/delete")
//	public String deleteCart(HttpServletRequest request, HttpServletResponse response,
//			Long skuId){
//		cartService.removeCart(request, response, skuId);
//		return "redirect:listCart.do";
//	}
//	
//	/**
//	 * 验证购物车的库存
//	 * @param request
//	 * @param response
//	 */
//	@RequestMapping("/validCarStock.do")
//	public void validCarStock(HttpServletRequest request, HttpServletResponse response){
//		String result = cartService.validCarStock(request, response);
//		ECPSUtils.printJSON(result, response);
//	}
	
}
